<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>封装变量</title>
</head>

<body>
    <script>
    var mult = (function () {
        var cache = {};
        var calculate = function () { // 封闭 calculate 函数
            var a = 1;
            for (var i = 0, l = arguments.length; i < l; i++) {
                a = a * arguments[i];
            }
            return a;
        };
        return function () {
            var args = Array.prototype.join.call(arguments, ',');
            if (args in cache) {
                return cache[args];
            }
            return cache[args] = calculate.apply(null, arguments);
        }
    })();
    </script>
</body>

</html>